package com.wc.blue_bridge_history.Java13B.B_寻找2020;

import java.io.*;

/**
 * @Author congge
 * @Date 2024/3/24 10:53
 * @description https://www.lanqiao.cn/paper/3890/problem/1065/
 */
public class Main {
    public static void main(String[] args) {
        File file = new File("D:\\javaPro\\algorithm-learning-luogu\\src\\com\\wc\\blue_bridge_history\\Java13B\\B_寻找2020\\ss.txt");
        BufferedReader br = null;
        try {
            br = new BufferedReader(new FileReader(file));
            int line = 0;
            String tmp = null;
            while ((tmp = br.readLine()) != null) {
                g[line] = tmp.toCharArray();
                line++;
            }
            long res = 0;
            n = line;
            m = g[0].length;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (g[i][j] == '2') res += dfs(i, j);
                }
            }
            System.out.println(res);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    static int n, m;
    static char[][] g = new char[10000][2];

    static int dfs(int x, int y) {
        int res = 0;
        if (x + 3 < n && g[x + 1][y] == '0' && g[x + 2][y] == '2' && g[x + 3][y] == '0') res++;
        if (y + 3 < m && g[x][y + 1] == '0' && g[x][y + 2] == '2' && g[x][y + 3] == '0') res++;
        if (y + 3 < m && x + 3 < n && g[x + 1][y + 1] == '0' && g[x + 2][y + 2] == '2' && g[x + 3][y + 3] == '0') res++;
        return res;
    }
}
